using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ChangeColor : StateMachineBehaviour
{

    private SpriteRenderer spriteRenderer;
    private Material material;

    private Color purpleMask = new Color(255f/255f,0,0,0);
    private Color purpleReplace = new Color(116f/255f, 174/255f, 224f/255f, 255f/255f);

    private Color redMask = new Color(0, 0, 255f/255f, 0);
    private Color redReplace = new Color(214f/ 255f, 156f/ 255f, 109f/255f, 255f/255f);


    Vector3Int[] strongColors = new Vector3Int[] {
    new Vector3Int(211,91,77), new Vector3Int(180, 57, 43), new Vector3Int(121, 32, 20), new Vector3Int(76, 29, 24)
    };
    Vector3Int[] skyColors = new Vector3Int[] {
    new Vector3Int(121, 95, 195), new Vector3Int(95, 69, 148), new Vector3Int(66, 49, 107), new Vector3Int(49, 36, 74)
    };

    public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        spriteRenderer = GameObject.FindGameObjectWithTag("TiGa").GetComponent<SpriteRenderer>();
        material = spriteRenderer.material;
        int form = animator.GetInteger("form");
        if (form == 1)
        {
            //material.SetFloat("_Range", 0.7f);
            //material.SetColor("_MaskColor", purpleMask);
            //material.SetColor("_ReplaceColor", purpleReplace);
            for(int i = 0; i < 4; i++)
            {
                material.SetColor("_Color" + (i + 1) + "in", new Color(strongColors[i].x / 255f, strongColors[i].y / 255f, strongColors[i].z / 255f));
                material.SetColor("_Color" + (i + 1) + "out", new Color(skyColors[i].x / 255f, skyColors[i].y / 255f, skyColors[i].z / 255f));
            }
            //animator.speed = 1.5f;
            
        }else if(form == 2) 
        {
            for (int i = 0; i < 4; i++)
            {
                material.SetColor("_Color" + (i + 1) + "in", new Color(skyColors[i].x / 255f, skyColors[i].y / 255f, skyColors[i].z / 255f));
                material.SetColor("_Color" + (i + 1) + "out", new Color(strongColors[i].x / 255f, strongColors[i].y / 255f, strongColors[i].z / 255f));
            }
           // animator.speed = 0.7f;
        }
 
    }
}
